package dm;

import java.sql.CallableStatement;
import java.sql.Connection;

import database.DBConnection;

public class LoggerDM {
	
	public void loginLog(int userId) throws Exception{
		Connection con = DBConnection.getConnection();
		CallableStatement statement = null;

		try {
				statement = con.prepareCall("{call LOG_PKG.LOGIN_LOG(?)}");
				statement.setInt(1,userId);
				statement.execute();
				statement.close();
				DBConnection.closeConnection(con);
		} catch (Exception e) {
			try {
				statement.close();
			} catch (Exception exception) {
			}
			try {
				DBConnection.closeConnection(con);
			} catch (Exception exception) {
			}
			throw e;
		}
	}

	
	public void logoutLog(int userId) throws Exception{
		Connection con = DBConnection.getConnection();
		CallableStatement statement = null;

		try {
				statement = con.prepareCall("{call LOG_PKG.LOGOUT_LOG(?)}");
				statement.setInt(1,userId);
				statement.execute();
				statement.close();
				DBConnection.closeConnection(con);
		} catch (Exception e) {
			try {
				statement.close();
			} catch (Exception exception) {
			}
			try {
				DBConnection.closeConnection(con);
			} catch (Exception exception) {
			}
			throw e;
		}
	}
	

	public void ProductOpenLog(int userId, int productId) throws Exception{
		Connection con = DBConnection.getConnection();
		CallableStatement statement = null;

		try {
				statement = con.prepareCall("{call LOG_PKG.PRODUCT_OPEN_LOG(?,?)}");
				statement.setInt(1,userId);
				statement.setInt(2,productId);
				statement.execute();
				statement.close();
				DBConnection.closeConnection(con);
		} catch (Exception e) {
			try {
				statement.close();
			} catch (Exception exception) {
			}
			try {
				DBConnection.closeConnection(con);
			} catch (Exception exception) {
			}
			throw e;
		}
	}



	public void ProductCloseLog(int userId, int productId) throws Exception{
		Connection con = DBConnection.getConnection();
		CallableStatement statement = null;

		try {
				statement = con.prepareCall("{call LOG_PKG.PRODUCT_CLOSE_LOG(?,?)}");
				statement.setInt(1,userId);
				statement.setInt(2,productId);
				statement.execute();
				statement.close();
				DBConnection.closeConnection(con);
		} catch (Exception e) {
			try {
				statement.close();
			} catch (Exception exception) {
			}
			try {
				DBConnection.closeConnection(con);
			} catch (Exception exception) {
			}
			throw e;
		}
	}

}
